<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>动态组件</h2>
      <button @click="str = 'Child1'">com1</button>
      <button @click="str = 'Child2'">com2</button>
      <button @click="str = 'Child3'">com3</button>

      <!-- <child1 v-if="active === 1"></child1>
      <child2 v-if="active === 2"></child2>
      <child3 v-if="active === 3"></child3> -->

      <!-- 动态组件 -->
      <!-- component标签必须要配合is属性 -->
      <!-- is属性写字符串，等于组件注册的名字，就会将这个组件渲染在这个地方 -->
      <component :is="str"></component>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const Child1 = {
        template: `
          <div>child1组件</div>
        `,
      };

      const Child2 = {
        template: `
          <div>child2组件</div>
        `,
      };

      const Child3 = {
        template: `
          <div>child3组件</div>
        `,
      };

      createApp({
        data() {
          return {
            // active: 1,
            str: "Child1",
          };
        },
        components: {
          Child1,
          Child2,
          Child3,
        },
      }).mount("#app");
    </script>
  </body>
</html>
